<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
</html>

<script>
const school2205 = [
  { name: '恒奥01', age: 21, home: '淄博-1' },
  { name: '恒奥02', age: 21, home: '淄博-2' },
  { name: '恒奥03', age: 21, home: '淄博-3' },
  { name: '恒奥04', age: 21, home: '淄博-4' },
  { name: '恒奥05', age: 21, home: '淄博-5' },
  { name: '恒奥06', age: 21, home: '淄博-6' },
]

// Students
/*
  function Students(list) {
    this.map = new Map();
    list.forEach(item => {
      this.map.set(item.name, item);
    })
  }

  // 向 构造函数的 原型对象上 添加方法 或 属性
    // 好处：任何 实例对象 都共用 原型对象上的 属性 和 方法
      // 什么是原型对象： 构造函数.prototype  -> 就是 原型对象
  Students.prototype.get = function(name) {
    return this.map.get(name);
  }

  const s = new Students(school2205);
  
  console.log(s.get('恒奥05'));
*/

class Students {
  constructor(list) {
    this.map = new Map();
    list.forEach(item => {
      this.map.set(item.name, item);
    })
  }

  get(name) {
    return this.map.get(name);
  }
}

const s = new Students(school2205);
  
console.log(s.get('恒奥05'));





</script>